/**
 * Created by Administrator on 2017/3/28.
 */


/**
 * Created by Administrator on 2017/3/13.
 */
/*global $, document, window, setTimeout, navigator, console, location*/
/*$(document).ready(function() {

    'use strict';

    var usernameError = true,
        emailError = true,
        passwordError = true,
        passConfirm = true;

    // Detect browser for css purpose
    if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1) {
        $('.form form label').addClass('fontSwitch');
    }


    // Label effect
    $('input').focus(function() {

        $(this).siblings('label').addClass('active');
    });

    // Form validation
    $('input').blur(function() {
        // User Name
        if ($(this).hasClass('usrName')) {
            if ($(this).val().length === 0) {
                $(this).siblings('span.error').text('Please type your full name').fadeIn().parent('.form-group').addClass('hasError');
                usernameError = true;
            } else if ($(this).val().length > 1 && $(this).val().length <= 6) {
                $(this).siblings('span.error').text('Please type at least 6 characters').fadeIn().parent('.form-group').addClass('hasError');
                usernameError = true;
            } else {
                $(this).siblings('.error').text('').fadeOut().parent('.form-group').removeClass('hasError');
                usernameError = false;
            }
        }
        // Email
        if ($(this).hasClass('userEmail')) {
            if ($(this).val().length == '') {
                $(this).siblings('span.error').text('Please type your email address').fadeIn().parent('.form-group').addClass('hasError');
                emailError = true;
            } else {
                $(this).siblings('.error').text('').fadeOut().parent('.form-group').removeClass('hasError');
                emailError = false;
            }
        }

        // PassWord
        if ($(this).hasClass('Password')) {
            if ($(this).val().length < 8) {
                $(this).siblings('span.error').text('Please type at least 8 charcters').fadeIn().parent('.form-group').addClass('hasError');
                passwordError = true;
            } else {
                $(this).siblings('.error').text('').fadeOut().parent('.form-group').removeClass('hasError');
                passwordError = false;
            }
        }

        // PassWord confirmation
        if ($('.Password').val() !== $('.passConfirm').val()) {
            $('.passConfirm').siblings('.error').text('Passwords don\'t match').fadeIn().parent('.form-group').addClass('hasError');
            passConfirm = false;
        } else {
            $('.passConfirm').siblings('.error').text('').fadeOut().parent('.form-group').removeClass('hasError');
            passConfirm = false;
        }

        // label effect
        if ($(this).val().length > 0) {
            $(this).siblings('label').addClass('active');
        } else {
            $(this).siblings('label').removeClass('active');
        }

    });


    /!*!// form switch
    $('a.switch').click(function(e) {
        $(this).toggleClass('active');
        e.preventDefault();

        if ($('a.switch').hasClass('active')) {
            $(this).parents('.form-peice').addClass('switched').siblings('.form-peice').removeClass('switched');
        } else {
            $(this).parents('.form-peice').removeClass('switched').siblings('.form-peice').addClass('switched');
        }
    });*!/


    // Form submit
    $('form.modify').submit(function(event) {
        // event.preventDefault();  //默认不执行submit
        console.log("注册跳转 JS ");
        if (usernameError == true || emailError == true || passwordError == true || passConfirm == true) {
            $('.userEmail, .Password, .passConfirm').blur();

            /!*  if(!isError)
             {
             $('form.signup-form').submit();
             }*!/
        } else {
            $('.signup, .login').addClass('switched');

            setTimeout(function() {
                $('.signup, .login').hide();
            }, 700);
            setTimeout(function() {
                $('.brand').addClass('active');
            }, 300);
            setTimeout(function() {
                $('.heading').addClass('active');
            }, 600);
            setTimeout(function() {
                $('.success-msg p').addClass('active');
            }, 900);
            setTimeout(function() {
                $('.success-msg a').addClass('active');
            }, 1050);
            setTimeout(function() {
                $('.form').hide();
            }, 700);
        }
    });

    // Reload page
    /!*  $('a.profile').on('click', function() {
     location.reload(true);
     });*!/

});*/



function modifyPassword() {
    //debugger;
        var formData = new FormData();
        formData.append("userEmail", document.getElementById("modifyinput1").value);
        formData.append("Password", document.getElementById("modifyinput2").value);
        console.log(formData);
        $.ajax({
            url: "/modifyPassword",
            type: "post",
            data: formData,
            //async: false,
            cache: false,
            contentType: false,
            processData: false,
            success: function (data) {
                alert(data);
                //console.log("修改密码成功");
                //setTimeout("location.reload()",100);//页面刷新
            },
            error: function (data) {
                alert("错误！！" + data);
            }
        });

}


function forgetPass(){
    var formData = new FormData();
    formData.append("userEmail", document.getElementById("userEmailinput").value);
    console.log(formData);
    $.ajax({
        url: "/forgetPassword",
        type: "post",
        data: formData,
        //async: false,
        cache: false,
        contentType: false,
        processData: false,
        success: function (data) {
            $("#message").append(data);
            alert(data);
            //setTimeout("location.reload()",100);//页面刷新
        },
        error: function (data) {
            $("#message").append(data);
            alert("错误！！" + data);
        }
    });

}